<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>mutations</title>
    </head>
    <body>
        <script src="../dist/vue-2.6.14.js"></script>

        <div id="app">
            <div>count: {{ count }}</div>
            <div>
                <span>Counter: </span>
                <Counter></Counter>
            </div>
            <button @click="inc">click</button>
        </div>

        <script>
            const state = new Vue({
                data() {
                    return {
                        count: 1,
                    };
                },

                watch: {
                    count(val) {
                        console.log('watch:', val);
                    },
                },

                methods: {
                    inc() {
                        this.count++;
                    },
                },
            });

            const Counter = {
                name: 'Counter',
                render: (h) => h('span', state.count),
            };

            const instance = new Vue({
                el: '#app',
                data() {
                    return {
                        // 为什么此处的 count 不跟随 state.count 变化？
                        // 但是 Counter 的跟随变化？
                        count: state.count,
                    };
                },
                components: {
                    Counter,
                },
                methods: {
                    inc() {
                        state.inc();
                    },
                },
            });
        </script>
    </body>
</html>
